package com.pet.petadoption.adoption.biz.impl;

import com.pet.petadoption.adoption.biz.AdoptionBiz;
import com.pet.petadoption.adoption.entity.Adoption;
import com.pet.petadoption.adoption.mapper.AdoptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdoptionBizImpl implements AdoptionBiz {

//    @Autowired
    @Resource
    AdoptionMapper adoptionMapper;

    @Override
    public List<Adoption> findAllAdoption(Integer index, Integer size,Boolean isAdopted) {
        //        计算上一页最后一条数据
        int newIndex = (index-1)*size;
        Map<String,Object> map = new HashMap<>();
        map.put("index" ,newIndex);
        map.put("size",size);
        map.put("isAdopted",isAdopted);
        return adoptionMapper.findAdoption(map);
    }

    @Override
    public Boolean delAdoptionById(Integer id) {
        return adoptionMapper.delAdoptionById(id);
    }

    @Override
    public Adoption findById(Integer id, Boolean isAdopted) {
        Map<String,Object> map = new HashMap<>();
        map.put("id" ,id);
        map.put("isAdopted",isAdopted);
        return adoptionMapper.findById(map);
    }

    @Override
    public List<Adoption> findByUname(String uname, Boolean isAdopted) {
        Map<String,Object> map = new HashMap<>();
        map.put("uname" ,uname);
        map.put("isAdopted",isAdopted);
        return adoptionMapper.findByUname(map);
    }

    @Override
    public boolean request(Integer pet_id,Integer adopter_id) {
        return adoptionMapper.request(pet_id,adopter_id) ;
    }

    @Override
    public Boolean delNoAdoptionById(Integer id) {
        return adoptionMapper.delNoAdoptionById(id);
    }

    @Override
    public Integer accessAdoption(Integer id) {
        return adoptionMapper.accessAdoption(id);
    }


}
